﻿using UnityEngine;
using System.Collections;

public class GfxWireLine : MonoBehaviour {

	public Wire inputWire;
	public LineRenderer outputLine;
	public Vector3 offset;
	public Vector3 anchorStart;
	public Vector3 anchorEnd;

	public Vector3 start;
	public Vector3 end;

	// Update is called once per frame
	void Update () {

		
		if (inputWire == null) inputWire = gameObject.GetComponent<Wire> ();		
		if (outputLine == null) outputLine = gameObject.GetComponent<LineRenderer> ();
	
		Neuron input = inputWire.neuronInput;
		Neuron output = inputWire.neuronOutput;
		
		start = input.gameObject.transform.position;
		end = output.gameObject.transform.position;

		float cs, ce;
		cs = inputWire.probeInputFloat;
		ce = inputWire.probeOutputFloat;
		outputLine.SetColors (new Color(cs, cs, cs, 1), new Color(ce, ce, ce, 1));
		//outputLine.SetColors (Color.red, Color.grey);
		float cm = (cs + ce) / 2;
		//outputLine.material.color = Color.red;// * ce;

		start = start + (Vector3)(input.gameObject.transform.localToWorldMatrix * anchorStart);
		end = end + (Vector3)(output.gameObject.transform.localToWorldMatrix * anchorEnd);

		outputLine.SetPosition (0, start + offset);
		outputLine.SetPosition (1, end + offset);

	}
}
